package com.serverTechnology.resource.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.serverTechnology.resource.entity.DeviceEntity;
import com.serverTechnology.resource.entity.DispositionEntity;
import com.serverTechnology.resource.entity.dto.DeviceDto;
import com.serverTechnology.resource.entity.dto.DevicePageDto;
import com.serverTechnology.resource.entity.dto.DeviceUpdateDto;
import com.serverTechnology.resource.entity.vo.DeviceDetailVo;
import com.serverTechnology.teamsGroups.entity.GroupUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.validation.annotation.Validated;
import com.serverTechnology.resource.service.IDeviceService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.web.bind.annotation.*;


/**
 * 设备类型表 接口
 *
 * @author 王烁
 * @since 2024-07-28
 */
@Api(tags = "设备类型表的接口")
@RestController
@RequestMapping("/device")
@ApiResource(name = "设备类型表的接口")
public class DeviceController {

    @Resource(name = "DeviceServiceImpl")
    private IDeviceService iDeviceService;

    /**
     * 新增设备类型
     *
     * @param device
     * @return
     */
    @ApiOperation("新增设备类型")
    @PostMapping("/insertDevice")
    public ResponseData add(@RequestBody @Validated DeviceDto device) {
        iDeviceService.add(device);
        return new SuccessResponseData("添加成功");
    }

    /**
     * 分页查询
     * @param detail 查询条件
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public ResponseData<PageResult<DeviceEntity>> pageAll(DevicePageDto detail) {
        return new SuccessResponseData(iDeviceService.pageAll(detail));
    }

    /**
     * 查询详情根据id
     * 1正常，2则是树型结构
     * @param id
     * @return
     */
    @ApiOperation("查询详情")
    @GetMapping("/detail")
    public ResponseData<DeviceDetailVo> detail(@RequestParam(required = false,name = "id") Long id,@RequestParam(required = false,name = "type")  Integer type) {
        DeviceDetailVo deviceDetailVo = iDeviceService.detail(id,type);
        return new SuccessResponseData(deviceDetailVo);
    }

    /**
     * 删除类型管理
     *
     * @param id  类型id
     * @return
     */
    @ApiOperation("删除类型管理")
    @DeleteMapping("/deleteDevice")
    public ResponseData deleteDevice(@NotNull(message = "参数不能为null")Long id) {
        iDeviceService.deleteDevice(id);
        return new SuccessResponseData("删除成功");
    }



    /**
     * 修改
     *
     * @param device
     * @return
     */
    @ApiOperation("修改")
    @PostMapping("/updateByDevice")
    public ResponseData updateByDevice(@RequestBody @Validated DeviceUpdateDto device) {
        iDeviceService.updateByDevice(device);
        return new SuccessResponseData("修改成功");
    }



}
